//
//  XWTableViewCell_b.m
//  网易新闻
//
//  Created by dllo on 15/9/21.
//  Copyright (c) 2015年 Lx. All rights reserved.
//

#import "XWTableViewCell_b.h"
#import "SDWebImage/UIImageView+WebCache.h"
#import "Settings.h"
@interface XWTableViewCell_b()
@property(nonatomic, retain)UILabel *lab1;
@property(nonatomic, retain)UILabel *lab2;
@property(nonatomic, retain)UIImageView *lab3;
@property(nonatomic, retain)UILabel *lab4;
@end
@implementation XWTableViewCell_b
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.selectedBackgroundView = [[[UIView alloc] initWithFrame:self.frame] autorelease];
        self.selectedBackgroundView.backgroundColor = [[Settings shareSettings]color:GrayToBlack];
        
        self.lab1 = [[UILabel alloc]init];
        self.lab1.textColor = [[Settings shareSettings]color:BlackToWhite];
        [self.contentView addSubview:_lab1];
        [_lab1 release];
        self.lab2 = [[UILabel alloc]init];
        self.lab2.textColor = [UIColor lightGrayColor];
        self.lab2.font = [UIFont systemFontOfSize:14];
        self.lab2.numberOfLines = 0;
        [self.lab2 sizeToFit];
        [self.contentView addSubview:_lab2];
        [_lab2 release];
        self.lab3 = [[UIImageView alloc]init];
        self.lab3.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_lab3];
        [_lab3 release];
        self.lab4 = [[UILabel alloc]init];
        self.lab4.textColor = [UIColor lightGrayColor];
        self.lab4.font = [UIFont systemFontOfSize:14];
        self.lab4.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_lab4];
        [_lab4 release];
        
        [self notificationHandle];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.lab1.frame = CGRectMake(10, 10, 355, 20);
    self.lab2.frame = CGRectMake(10, 160, 355, 40);
    self.lab3.frame = CGRectMake(10, 40, 355, 120);
    self.lab4.frame = CGRectMake(275, 185, 90, 20);
}

- (void)setMod:(XinwenModel *)mod{
    if (_mod != mod) {
        [_mod release];
        _mod = [mod retain];
    }
    self.height = 215;
    
    self.lab1.text= mod.title;
    self.lab2.text = mod.digest;
    [self.lab3 sd_setImageWithURL:mod.imgsrc placeholderImage:nil];
    self.lab4.text = [NSString stringWithFormat:@"%ld跟帖", mod.replyCount];
}

- (void)notificationHandle{
    [[NSNotificationCenter defaultCenter]addObserverForName:@"changeBackgroundColor" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        self.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.lab1.textColor = [[Settings shareSettings]color:BlackToWhite];
        self.selectedBackgroundView.backgroundColor = [[Settings shareSettings]color:GrayToBlack];
    }];
}

- (void)dealloc{
    [_lab1 release];
    [_lab2 release];
    [_lab3 release];
    [_lab4 release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
